home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: Does C convert float to double internally ?
- Date: 3 Apr 1996 10:46:16 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4juh1oINNo39@keats.ugrad.cs.ubc.ca>
- References: <4jsllh$hkf@harbinger.cc.monash.edu.au>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <4jsllh$hkf@harbinger.cc.monash.edu.au>,
- Biggles Cheung <bcheung@yoyo.cc.monash.edu.au> wrote:
- >I was told that C compiler automatically converts "float" variable
- >internally to "double" for + - * / , etc operations. Is this true?
-
- ANSI allows the compiler to use float precision for operations between two
- float operands. If you want the operation to be done in a higher precision, you
- cast both operands to double.
-
- float x, y, z;
-
- z = (double) x / (double) y;
-
- >Can I force the C compiler not to do the conversion as I have an
- >assignment on finding out various computing errors of different
- >precisions?
-
- I'm not sure about this one. I'd have to check whether the standard compliant
- implementation _must_ use float precision. As far as I know, it is _free_ to
- use the smaller precision to do the operation, but is not required to.
-
- If the implementation insists on using double precision math internally (or
- even something more precise---many floating point units will use extra
- precision) there is little you can do.
-
- >My advice from the lecturer is to have temporary variable of
- >float to split a long equation to smaller step so that I can maximize
- >the impact of single precision number on the evaluation. Is this
- >feasible?
-
- Sure, but it won't affect a particular operation like / if the compiler insists
- on doing it in a high precision. Converting to float will only truncate the
- _result_ to a lower precision.
- --
-
-